﻿Ext.ns('suce.dr');

suce.dr.aprobacion = function (config) {

    return new Ext.Panel(Ext.apply({

        title: 'Documento Resolutivo de Aprobación',
        layout: 'border',

        iddr: null,                 // Parámetro
        idsolicitud: null,        // Parámetro

        initComponent: function () {
            var me = this,
                form, north;

            //
            north = {
                region: 'north',
                height: 75,
                baseCls: 'x-plain',
                layout: {
                    type: 'hbox',
                    padding: '2',
                    align: 'stretch'
                },
                defaults: { headerPosition: 'bottom', border: false },
                items: [
                    {
                        xtype: 'buttongroup',
                        title: 'Acciones',
                        defaults: { scale: 'medium', iconAlign: 'top' },
                        items: [
                            BUTTON('Guardar', me.ok, me, { iconCls: 'tb-save24' })
                        ]
                    }
                ]
            };

            form = new Ext.form.Panel({
                baseCls: 'x-plain',
                bodyPadding: 10,
                height: 130,
                region: 'center',
                fieldDefaults: { labelWidth: 100 },
                items: [
                    HIDDEN('iddr'),
                    TEXT('numedr', 'Número', 50),
                    TEXT('numfile', 'Número File', 50),
                    DATE('fechbroad', 'F. Transmisión'),
                    DATE('fechvalida', 'F. Validación')
                ]
            });

            me.grid = new suce.upload.Grid({
                region: 'south',
                height: '50%',
                split: true,
                folder: 'S' + me.idsolicitud
            });

            me.items = [north, form, me.grid];

            Ext.Panel.prototype.initComponent.call(me);

            me.form = form.form;

            me.on({
                scope: me,
                'afterrender': me.reload
            });
        },

        ok: function () {
            var me = this,
                p = Ext.apply({ C: 'DRA', S: 'UPDATE' }, me.form.getValues());
            postServer('gestor/dr.ashx', p, function () {

            }, me);
        },

        reload: function () {
            var me = this;
            callServer('gestor/dr.ashx', { C: 'DRA', S: 'GETBYID', iddr: me.iddr }, function (v) {
                v = Ext.decode(v);
                me.form.setValues(v.form);
            }, me);
        }

    }, config));
};




suce.dr.denegacion = function (config) {

    return new Ext.Panel(Ext.apply({

        title: 'Documento Resolutivo de Denegación',
        layout: 'border',

        iddr: null,                 // Parámetro
        idsolicitud: null,          // Parámetro

        initComponent: function () {
            var me = this,
                form, north;

            //
            north = {
                region: 'north',
                height: 75,
                baseCls: 'x-plain',
                layout: {
                    type: 'hbox',
                    padding: '2',
                    align: 'stretch'
                },
                defaults: { headerPosition: 'bottom', border: false },
                items: [
                    {
                        xtype: 'buttongroup',
                        title: 'Acciones',
                        defaults: { scale: 'medium', iconAlign: 'top' },
                        items: [
                            BUTTON('Guardar', me.ok, me, { iconCls: 'tb-save24' })
                        ]
                    }
                ]
            };

            form = new Ext.form.Panel({
                baseCls: 'x-plain',
                bodyPadding: 10,
                height: 130,
                region: 'center',
                fieldDefaults: { labelWidth: 100 },
                items: [
                    HIDDEN('iddr'),
                    TEXT('numedr', 'Número de DRD', 50),
                    TEXT('numfile', 'Número File', 50),
                    DATE('fechbroad', 'F. Transmisión'),
                    DATE('fechvalida', 'F. Validación'),
                    TEXTAREA('mensaje', 'Descripción', 4000, {width: 400})
                ]
            });

            me.grid = new suce.upload.Grid({
                region: 'south',
                height: '50%',
                split: true,
                folder: 'S' + me.idsolicitud
            });

            me.items = [north, form, me.grid];

            Ext.Panel.prototype.initComponent.call(me);

            me.form = form.form;

            me.on({
                scope: me,
                'afterrender': me.reload
            });
        },

        ok: function () {
            var me = this,
                p = Ext.apply({ C: 'DRD', S: 'UPDATE' }, me.form.getValues());
            postServer('gestor/dr.ashx', p, function () {
                //
            }, me);
        },

        reload: function () {
            var me = this;
            callServer('gestor/dr.ashx', { C: 'DRD', S: 'GETBYID', iddr: me.iddr }, function (v) {
                v = Ext.decode(v);
                me.form.setValues(v.form);
            }, me);
        }

    }, config));
};
